/**
 * 
 */
package jvs.peer.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * @author qiangli
 *
 */
public class Net {

	/**
	 * 
	 */
	private Net() {
	}

	public static String ip() {

		try {
			Enumeration<?> nis = NetworkInterface.getNetworkInterfaces();
			while (nis.hasMoreElements()) {
				NetworkInterface ni = (NetworkInterface) nis.nextElement();
				Enumeration<?> ias = ni.getInetAddresses();
				while (ias.hasMoreElements()) {
					InetAddress ia = ((InetAddress) ias.nextElement());
					if (ia.isLoopbackAddress()) {
						continue;
					}
					String addr = ia.getHostAddress();
					return addr;
				}
			}
		} catch (Exception e) {
			//
		}
		return null;
	}
}
